<?php

/**
 * 
 *
 * @version $Id: css.inc.php,v 1.7 2005/01/05 13:36:39 phppc Exp $
 * @copyright 2004 
 **/

$this->uf_field[1] = "name";
	$this->uf_input[1]["ml"] = 50;
	$this->uf_input[1]["size"] = 15;
$this->uf_field[2] = "css_code";
	$this->uf_input[2]["type"] = "textarea";
	$this->uf_input[2]["cols"] = 100;
	$this->uf_input[2]["rows"] = 14;

$css = $this->fun_sg2var("css");
$css = $this->uf_form_conf_def($css,array("show","edit","do_edit","new","del"),"show");

$this->module_new_value["action"] = "css";

if ($css == "show") {
	$erg = $this->db_abfrage_q("SELECT * FROM ".$this->config["prefix"]."css");
	$css_ones = "";
	while($db_css = $this->db_abfrage_fetch($erg)){
		$edit_link = $this->fun_make_link("admin.php","css=edit&css_id=".$db_css["id"]."");
		$this->tpl_load("css_one","admin/");
		$this->tpl_replace_vars(array("css_name" => $db_css["name"],"edit_link" => $edit_link,"css_id" => $db_css["id"]));
		$css_ones .= $this->tpl_output();
	} // while
	list($standard_css) = $this->db_abfrage("SELECT ".$this->config["prefix"]."css.css_code as css_code FROM ".$this->config["prefix"]."style LEFT JOIN ".$this->config["prefix"]."css ON (".$this->config["prefix"]."css.id=".$this->config["prefix"]."style.css_id) WHERE ".$this->config["prefix"]."style.id=\"".$this->db_config["default_style"]."\"");
	$var_array["css_code"] = $standard_css;
	$hidden_array["action"] = "css";
	$hidden_array["css"] = "new";
	$css_new_form = $this->uf_create_complete_form("admin_css_new_title",$hidden_array,"admin_css_new_submit","form_reset","complete_form","uf/","admin.php",$var_array,"admin_css_one_");
	unset($hidden_array,$var_array);
	$hidden_array["css"] = "del";
	$hidden_form = $this->uf_create_hidden_form($hidden_array);
	$this->tpl_load("css","admin/");
	$this->tpl_replace_vars(array("hidden_form" => $hidden_form,"css_ones" => $css_ones,"css_new_form" => $css_new_form));
	$nc_main = $this->tpl_output();
}elseif ($css == "new") {
	list($return,$abfrage1,$abfrage2) = $this->uf_create_array_conf("insert");
	$valid_input = $this->uf_form_conf($return);
	if ($valid_input == 1) {
		$this->db_abfrage_q("INSERT ".$this->config["prefix"]."css ($abfrage1) VALUES ($abfrage2)");
		$this->message_green[] = 16;
		$this->w_leitung["number"] = 8;
		$this->w_leitung["url"] = $this->fun_make_link("admin.php");
	}else {
		$this->message_red[] = 1;
		$this->w_leitung["number"] = 1;
	}
}elseif ($css == "edit") {
	$valid_id = $this->db_anzahl_zeilen("SELECT id FROM ".$this->config["prefix"]."css WHERE id = \"".$_GET["css_id"]."\"");
	if ($valid_id == 1) {
		$var_array = $this->db_abfrage_az("SELECT * FROM ".$this->config["prefix"]."css WHERE id = \"".$_GET["css_id"]."\"");
		$hidden_array["action"] = "css";
		$hidden_array["css"] = "do_edit";
		$hidden_array["css_id"] = $_GET["css_id"];
		$nc_main = $this->uf_create_complete_form("admin_css_edit_title",$hidden_array,"admin_css_edit_submit","form_reset","complete_form","uf/","admin.php",$var_array,"admin_css_one_");
	}else {
		$this->message_red[] = 11;
		$this->w_leitung["number"] = 8;
		$this->w_leitung["url"] = $this->fun_make_link("admin.php");
	}
}elseif ($css == "do_edit") {
	$valid_id = $this->db_anzahl_zeilen("SELECT id FROM ".$this->config["prefix"]."css WHERE id = \"".$_POST["css_id"]."\"");
	if ($valid_id == 1) {
		list($return,$abfrage) = $this->uf_create_array_conf("update");
		$valid_input = $this->uf_form_conf($return);
	    if ($valid_input == 1) {
	        $this->db_abfrage_q("UPDATE ".$this->config["prefix"]."css SET $abfrage WHERE id = \"".$_POST["css_id"]."\"");
			$this->message_green[] = 17;
			$this->w_leitung["number"] = 8;
			$this->w_leitung["url"] = $this->fun_make_link("admin.php","action=css");
	    }else {
			$this->message_red[] = 1;
			$this->w_leitung["number"] = 1;
		}
	}else {
		$this->message_red[] = 11;
		$this->w_leitung["number"] = 8;
		$this->w_leitung["url"] = $this->fun_make_link("admin.php","action=css");
	}
}elseif ($css == "del") {
	if (isset($_POST["del_css"])) {
	    $css_ids = array();
		list($standard_css) = $this->db_abfrage("SELECT ".$this->config["prefix"]."css.id as id FROM ".$this->config["prefix"]."style LEFT JOIN ".$this->config["prefix"]."css ON (".$this->config["prefix"]."css.id=".$this->config["prefix"]."style.css_id) WHERE ".$this->config["prefix"]."style.id=\"".$this->db_config["default_style"]."\"");
		$this->anzahl = 0;
		$this->anzahl_del = 0;
		foreach ($_POST["del_css"] as $css_id) {
			$anzahl_css = $this->db_anzahl_zeilen("SELECT id FROM ".$this->config["prefix"]."css");
			if($css_id != $standard_css AND $anzahl_css > 1) {
				array_push($css_ids,$css_id);
				$this->anzahl_del++;
			}
			$this->anzahl++;
		}
		if ($this->anzahl_del >= 1) {
		    $abfrage = $this->uf_create_where_part($css_ids);
			$this->db_abfrage_q("DELETE FROM ".$this->config["prefix"]."css WHERE $abfrage");
			$this->message_green[] = 18;
		}else $this->message_red[] = 12;
	}else $this->message_red[] = 13;
	$this->w_leitung["number"] = 8;
	$this->w_leitung["url"] = $this->fun_make_link("admin.php");
}

?>